package com.book.derecated.state;

import com.book.derecated.DeprecratedConstants;
import com.book.derecated.observer.DeprecatedAbstractObserver;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 订单状态基类,抽象被观察者类
 * @date 2023/11/21 22:33
 */
public abstract class DeprecatedAbstractOrderState {

    // 订单状态定义,待支付,待发货,待收获,订单完成
    protected final String ORDER_WAIT_PAY = "ORDER_WAIT_PAY";

    protected final String ORDER_WAIT_SEND = "ORDER_WAIT_SEND";

    protected final String ORDER_WAIT_RECEIVE = "ORDER_WAIT_RECEIVE";

    protected final String ORDER_FINISH = "ORDER_FINISH";

    // 关联抽象观察者
    protected final List<DeprecatedAbstractObserver> observers = DeprecratedConstants.OBSERVER_LIST;

    // 新增观察者
    public void addObserver(DeprecatedAbstractObserver observer){
        this.observers.add(observer);
    }

    // 移除观察者
    public void deleteObserver(DeprecatedAbstractObserver observer){
        this.observers.remove(observer);
    }

    // 定义通知观察者的方法
    public void notifyObserver(String orderId, String orderState){
        for (DeprecatedAbstractObserver observer : observers) {
            observer.orderStateHandle(orderId,orderState);
        }
    }

    // 创建订单
    protected DeprecatedOrder createOrder(String orderId,DeprecatedOrderContext context) {
        throw new IllegalStateException();
    }

    // 订单支付
    protected DeprecatedOrder payOrder(String orderId,DeprecatedOrderContext context) {
        throw new IllegalStateException();
    }

    // 订单发送
    protected DeprecatedOrder sendOrder(String orderId,DeprecatedOrderContext context) {
        throw new IllegalStateException();
    }

    // 订单签收
    protected DeprecatedOrder receiveOrder(String orderId,DeprecatedOrderContext context) {
        throw new IllegalStateException();
    }



}
